package hu.uszeged.inf.stud.prf.todo.dao.user;

import java.util.List;

import hu.uszeged.inf.stud.prf.todo.dao.core.GenericHibernateDAO;
import hu.uszeged.inf.stud.prf.todo.entity.user.User;

public class UserDAO extends GenericHibernateDAO<User, Long> {

	public UserDAO() {
		super(User.class);
	}

	public User getUserByName(String user) {
		StringBuilder query = new StringBuilder();
		query.append("from User user ");
		query.append("where user.name = :name");
		return (User) getSession().createQuery(query.toString())
				.setParameter("name", user)
				.uniqueResult();
	}

	@SuppressWarnings("unchecked")
	public List<User> getOtherUsers(User user) {
		StringBuilder query = new StringBuilder();
		query.append("from User user ");
		query.append("where user != :user");
		return getSession().createQuery(query.toString())
				.setParameter("user", user)
				.list();
	}
}
